package org.example;

import oracle.jdbc.pool.OracleDataSource;

import javax.sql.DataSource;
import java.sql.SQLException;

public class DataSourceFactory {

  private final String url;
  private final String username;
  private final String password;

  public DataSourceFactory(String url, String username, String password) {
    this.url = url;
    this.username = username;
    this.password = password;
  }

  public DataSource createDataSource() throws SQLException {
    OracleDataSource dataSource = new OracleDataSource();
    dataSource.setURL(url);
    dataSource.setUser(username);
    dataSource.setPassword(password);

    // 连接池配置（可选）
    dataSource.setImplicitCachingEnabled(true);  // 启用连接缓存
    dataSource.setConnectionCachingEnabled(true); // 启用连接池

    return dataSource;
  }
}